<template>
  <div class="company-home">
    <company-nav :logo='info.merchant.mer_avatar' v-if="isShowNav" />
    <Title :id="companyId" :info="companyInfo" :merchantInfo='merchantInfo' />
    <Nav :id="companyId"/>
    <home-swiper v-show="$route.name === 'CompanyHomeHome' || notSettled" :banner="info.mer_banner"/>
    <div class="body">
      <router-view />
    </div>
  </div>
</template>

<script>
import HomeSwiper from './children/HomeSwiper'
import Head from './children/Head'
import Nav from './children/Nav'
import Title from '@/views/company-home/children/Title'
import NotSettled from '@/views/company-home/children/NotSettled'
import { getMerchantHome, getMerchantDe } from '@/request/api'
import companyNav from './children/home/miniNav/index'

export default {
  name: 'CompanyHome',
  components: { NotSettled, Title, Nav, Head, HomeSwiper, companyNav },
  data() {
    return {
      isShowNav: false,
      companyId: '',
			info:{
				merchant:''
			},
			companyInfo:{
				merchant:""
			},
      notSettled: true,
      notCertified: true,
      merchantInfo:{}
    }
  },
  watch: {
    $route: {
      handler(val) {
      },
      immediate: true
    }
  },
  created() {
		this.companyId = this.$route.params.id
    this.getInfo()
    this.getDetailData()
    window.addEventListener('scroll', this.windowScroll)
	},
	methods:{
		getInfo(){
			getMerchantHome(this.companyId).then( res => {
				this.info = res.data;
        console.log(res.data,'info');
        this.merchantInfo = res.data.merchant;
        console.log(this.merchantInfo,'merchantInfo');
        localStorage.setItem('merchantInfo', JSON.stringify(res.data))
			})
    },
    getDetailData() {
      getMerchantDe(this.companyId).then( res => {
				this.companyInfo = res.data
        this.info.mer_banner = res.data.mer_banner
        console.log(this.companyInfo);
			}).catch(err => {
        this.$message.error(err.message)
      })
    },
    // 滚动显示miniNva导航栏
    windowScroll() {
      let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
      this.isShowNav = scrollTop >= 400
    }
	},
}
</script>

<style lang="scss" scoped>
.company-home {
  .body {
    background-color: rgb(243, 244, 247);
    padding: 60px 0;
    display: flex;
    justify-content: center;
  }
}
</style>
